package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.TargetTypeDao;
import com.bestv.search.common.model.TargetType;

import java.util.List;

public class TargetTypeDaoHibernate extends GenericDaoHibernate<TargetType, Long> implements TargetTypeDao {

    public TargetTypeDaoHibernate() {
        super(TargetType.class);
    }

    public TargetType getTargetById(Long id) {
        return super.get(id);
    }

    @SuppressWarnings("unchecked")
    public TargetType getTargetByName(String name) {
        List<TargetType> list = getHibernateTemplate().find("from TargetType t where t.name = ?", name);
        if (list == null || list.size() == 0)
            return null;
        return list.get(0);
    }

    public List<TargetType> getTargetTypes() {
        return super.getAll();
    }

    public TargetType saveTargetType(TargetType targetType) {
        return super.save(targetType);
    }
}
